package com.m3839.sdk.anti.bean;


import com.m3839.sdk.anti.constant.AntiConstant;
import com.m3839.sdk.common.base.BaseBean;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Description:HykbFcmConfig
 *
 * @author 陈宝阳
 * @create 2019/12/31 16: 33
 */
public class AntiBean extends BaseBean<AntiBean> {

  /**
   * 下次心跳请求间隔时长，单位秒
   */
  private int interval = 60;

  /**
   * 本次会话对应的token
   */
  private String token;

  /**
   * 还剩余的时间
   */
  private int remainingTime;

  /**
   * 返回用户实名信息，1：成年；2：未成年；3：未实名
   */
  private int idCardStatus;

  /**
   * 返回用户累计游戏时长，单位秒
   */
  private int playTime;

  /**
   * 认证状态（1：已认证，0：未认证）
   */
  private int verifyStatus;

  /**
   * 防沉迷UI体现的配置信息
   */
  private List<PopConfigBean> popConfigs;

  /**
   * 倒计时信息配置
   */
  private List<PopConfigBean> countDownBeans;

  /**
   * 结束游戏的操作
   */
  private PopConfigBean offLineBean;

  public void parseData(JSONObject dataJson) {

  }

  @Override
  public AntiBean parseBean(JSONObject dataJson) {
    if(dataJson == null) {
      return null;
    }
    interval = dataJson.optInt(AntiConstant.KEY_INTERVAL);
    token = dataJson.optString(AntiConstant.KEY_TOKEN);
    remainingTime = dataJson.optInt(AntiConstant.KEY_REMAINING_TIME);
    idCardStatus = dataJson.optInt(AntiConstant.KEY_IDCARD_STATUS);
    playTime = dataJson.optInt(AntiConstant.KEY_PLAY_TIME);

    JSONArray popConfigJsonArray = dataJson.optJSONArray(AntiConstant.KEY_POP_CONFIG);
    parsePopConfig(popConfigJsonArray);

    JSONArray countDownJsonArray = dataJson.optJSONArray(AntiConstant.KEY_COUNT_DOWN);
    parseCountDown(countDownJsonArray);

    JSONObject offLineJson = dataJson.optJSONObject(AntiConstant.KEY_OFF_LINE);
    parseOffLine(offLineJson);
    return this;
  }

  private void parsePopConfig(JSONArray popConfigJsonArray) {
    popConfigs = new ArrayList<>();
    if (popConfigJsonArray != null) {

      int len = popConfigJsonArray.length();
      for (int i = 0; i < len; i++) {
        JSONObject configJson = popConfigJsonArray.optJSONObject(i);
        popConfigs.add(new PopConfigBean(configJson));
      }
    }
  }

  private void parseCountDown(JSONArray popConfigJsonArray) {
    countDownBeans = new ArrayList<>();
    if (popConfigJsonArray != null) {

      int len = popConfigJsonArray.length();
      for (int i = 0; i < len; i++) {
        JSONObject configJson = popConfigJsonArray.optJSONObject(i);
        popConfigs.add(new PopConfigBean(configJson));
      }
    }
  }

  private void parseOffLine(JSONObject offLineJson) {
    if(offLineJson == null) {
      return;
    }
    offLineBean = new PopConfigBean(offLineJson);
  }

  public int getInterval() {
    return interval;
  }

  public String getToken() {
    return token;
  }

  public void resetToken() {
    token = null;
  }

  public int getRemainingTime() {
    return remainingTime;
  }

  public int getIdCardStatus() {
    return idCardStatus;
  }

  public int getPlayTime() {
    return playTime;
  }

  public List<PopConfigBean> getPopConfigs() {
    return popConfigs;
  }

  public List<PopConfigBean> getCountDownBeans() {
    return countDownBeans;
  }

  public PopConfigBean getOffLineBean() {
    return offLineBean;
  }
}
